<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 吧
  Date: 2020/12/1
  Time: 14:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>判断登录</title>
</head>
<%
    String username=request.getParameter("username");
    String password=request.getParameter("password");

    Class.forName("com.mysql.jdbc.Driver");
    String url="jdbc:mysql://localhost:3306/lixiuying";
    Connection connection= DriverManager.getConnection(url,"root","root");
    String sql="select * from users where uname=? and upass=?";
    PreparedStatement pstm=connection.prepareStatement(sql);
    pstm.setString(1,username);
    pstm.setString(2,password);
    ResultSet rs=pstm.executeQuery();
    if(rs.next())
    {
        session.setAttribute("username",username);
        response.sendRedirect("SelectNews.jsp");
    }
    else {
        out.print("<h2>账号或密码错误，3秒后返回登录页面</h2>");
        response.setHeader("refresh","3,url=LogOn.jsp");
    }
%>
<body>

</body>
</html>
